﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Maticsoft.Common;

namespace Maticsoft.Web.Admin.Shopping
{
    public partial class EditCategory : PageBase
    {
        BLL.BookCategory bll = new BLL.BookCategory();
        Model.BookCategory model = null;

        string id = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            Check("shopping", "modify");

            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                id = Request.QueryString["id"];

                if (!IsPostBack)
                {
                    GetData();
                }
            }
        }

        protected void GetData()
        {
            if (!string.IsNullOrEmpty(id))
            {
                model = bll.GetModel(int.Parse(id));
                txtTitle.Text = model.CategoryName;
                txtDetail.Text = model.Detail;
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(id))
            {
                model = bll.GetModel(int.Parse(id));
                model.CategoryName = txtTitle.Text.Trim();
                model.Detail = txtDetail.Text.Trim();
                model.ParentId = 0;
                model.Path = "0/";
                model.UpdateTime = DateTime.Now;
                model.IsActive = 1;
                bll.Update(model);
                MessageBox.ShowAndRedirect(this.Page, "修改成功", "Category.aspx");
            }
            else
            {
                model = new Model.BookCategory();
                model.CategoryName = txtTitle.Text.Trim();
                model.Detail = txtDetail.Text.Trim();
                model.ParentId = 0;
                model.Path = "0/";
                model.CreateTime = DateTime.Now;
                model.UpdateTime = DateTime.Now;
                model.IsActive = 1;
                bll.Add(model);
                MessageBox.ShowAndRedirect(this.Page, "添加成功", "Category.aspx");
            }
        }
    }
}